<?php defined('SYSPATH') or die('No direct script access.');

	class Model_Services_Family extends Model{
	
		public $family = NULL;
				
		public function count($criteria = false){
			return ORM::factory("dao_family")->where("patient_id","=",$this->id_patient)->count_all();
		}
		
		public function getAll(){
			return ORM::factory("dao_family")->find_all()->as_array();
		}
		
		/**
		*
		* get family from an id
		* @param int $minId
		* @param int $maxAmount
		* @return array of family
		*/
		public function getListFromMinID($minId, $maxAmount){
			return ORM::factory("dao_family")->where("id",">",$minId)->order_by("id", "ASC")->limit($maxAmount)->find_all()->as_array();
		}
		
		public function save($id, array $data){
			$this->family = ($id > 0) ? ORM::factory("dao_family",$id) : ORM::factory("dao_family");
			$this->family->family_name = $data['family_name'];
			$this->family->sex = $data['sex'];
			$this->family->save();
			return $this->family->id;
		}
		
		public function delete($id){
			$this->family = ORM::factory("dao_family",$id);
			$this->family->delete();
			return $id;
		}
		
		/**
		*
		* return an entity family by name
		* @param string $name
		* @return family 
		*/
		public function getByName($name){
			return ORM::factory("dao_family")->where("family_name","=",$name)->find();
		}
		
	}
?>